#include "ShopTreeModelDelegate.h"
#include "ShopTreeModel.h"

using namespace ecocity;

ShopTreeModelDelegate::ShopTreeModelDelegate( QObject *parent )
        : QItemDelegate( parent )
{
}

//---------------------------------------------------------------

void
ShopTreeModelDelegate::paint( QPainter *painter,
                              const QStyleOptionViewItem &option,
                              const QModelIndex &index ) const
{
    QStyleOptionViewItem my_option = option;
    my_option.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;

    QString text;

    switch ( index.column( ) )
    {
    case ShopTreeModel::INVOICE_TOTAL: // same as ShopTreeModel::ITEM_TOTAL
    case ShopTreeModel::INVOICE_PROFIT:
    {
        float price = index.model()->data( index, Qt::DisplayRole ).toFloat( );
        text = QString::number( price, 'f', 2 );
        text.append( QString( " EUR" ) );
        break;
    }
    default:
        QItemDelegate::paint( painter, option, index );
        return; // return is fine here
    }

    drawDisplay( painter, my_option, my_option.rect, text );
    drawFocus( painter, my_option, my_option.rect );
}



